package com.wosiliujing.learning.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wosiliujing.learning.admin.po.SysLog;
import com.wosiliujing.learning.annotation.Inner;
import com.wosiliujing.learning.constant.CommonConstants;
import com.wosiliujing.learning.service.SysLogService;
import com.wosiliujing.learning.util.R;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @author: liujing
 * @date: 2019/5/17 22:33
 * @description:
 */
@AllArgsConstructor
@RestController
@RequestMapping("/log")
public class SysLogController {

    private final SysLogService sysLogService;

    /**
     * 分页查询系统日志
     * @param page 分页参数
     * @param sysLog 分页条件
     * @return
     */
    @RequestMapping("/page")
    public R getSysLogPage(Page page, SysLog sysLog){
        return R.data(sysLogService.page(page,Wrappers.query(sysLog)));
    }

    /**
     * 删除日志
     * @param id 日志id
     * @return 删除结果
     */
    @PreAuthorize("@pms.hasPermisssion('sys_log_del')")
    @DeleteMapping("/delete/{id}")
    public R removeById(@PathVariable String id){
        return sysLogService.removeById(id)?R.ok():R.error(CommonConstants.DELETE_FAIL);
    }

    /**
     * 保存日志
     * @param sysLog 日志信息
     * @return 保存结果
     */
    @Inner
    @PostMapping("/save")
    public R save(@RequestBody SysLog sysLog){
        return sysLogService.save(sysLog)?R.ok():R.error(CommonConstants.SAVE_FAIL);
    }


}
